package com.earthea.chatbot.common.exception;

import com.earthea.common.exception.IErrorCode;
import com.earthea.chatbot.common.entity.HttpCodeEnum;

/**
 * 公共异常
 */
public class ServiceException extends RuntimeException implements IErrorCode {
    private int code;

    private String message;

    public ServiceException() {
        this.code = HttpCodeEnum.FAIL.getCode();
        this.message = HttpCodeEnum.FAIL.getMsg();
    }

    public ServiceException(String message) {
        this.code = HttpCodeEnum.FAIL.getCode();
        this.message = message;
    }

    public ServiceException(IErrorCode errorCode) {
        super(errorCode.getCode() + ":" + errorCode.getMsg());
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    public ServiceException(IErrorCode errorCode, String message) {
        super(errorCode.getCode() + ":" + message);
        this.code = errorCode.getCode();
        this.message = message;
    }

    public ServiceException(Throwable cause) {
        super(cause);
    }

    public ServiceException(IErrorCode errorCode, Throwable cause) {
        super(cause);
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return message;
    }
}
